define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http,$http) {

		//返回信息
		return {
			//发送红包
			packets_grant: function(group_id, redmoney, rednum, redtype, redmsg,paypass, callback) {
				Http.post({
					method: 'chat.group.preparered',
					group_id: group_id,
					redmoney: redmoney,
					rednum: rednum,
					redtype: redtype,
					redmsg:redmsg,
					paypass:paypass
				}, function(result) {
					if(callback)
						callback(result);
				}, function(e) {

				}, function() {

				});
			},
			get_groupinfo:function(group_id,callback,calldone){
				Http.post({
						method:'chat.group.getgroupinfo',
						group_id:group_id
					},function(result){
						if(callback)
						callback(result.result);
					},function(e){
					
				},function(){
					if(calldone)
					calldone();
				});
			},
		 get_message:function(siginfo,login_code,chat_url,msgId,callback,calldone){
		 	var html_url = chat_url+'/message/getChatMsg?';
		 	html_url +='sigVer='+siginfo.sigVer;
		 	html_url +='&nonce='+siginfo.nonce;
		 	html_url +='&ts='+siginfo.ts;
		 	html_url +='&sig='+siginfo.sig;
		 	html_url +='&loginCode='+login_code;
		 	html_url +='&lastMsgId='+msgId;
		 	$http({
		 		url:html_url,
		 		method:'GET',
		 	}).success(function(data){
		 		if(callback)
		 		callback(data);
		 	}).error(function(e){
		 		
		 	}).finally(function(){
		 		if(calldone)
		 		calldone();
		 	})
		 },
		 get_histroy:function(siginfo,login_code,chat_url,msgId,groupId,callback,calldone){
		 	var html_url = chat_url+'/message/getChatMsgHistoryByDate?';
		 	html_url +='sigVer='+siginfo.sigVer;
		 	html_url +='&nonce='+siginfo.nonce;
		 	html_url +='&ts='+siginfo.ts;
		 	html_url +='&sig='+siginfo.sig;
		 	html_url +='&loginCode='+login_code;
		 	html_url +='&msgId='+msgId;
		 	html_url +='&groupId='+groupId;
		 	html_url +='&frDate= ';
		 	html_url +='&toDate= ';
		 	html_url +='&limits='+20;
		 	$http({
		 		url:html_url,
		 		method:'GET',
		 	}).success(function(data){
		 		if(callback)
		 		callback(data);
		 	}).error(function(e){
		 		
		 	}).finally(function(){
		 		if(calldone)
		 		calldone();
		 	})
		 },
		 check_bag:function(red_id,callback){
		 	Http.post({
		 		method:'chat.group.checkopen',
		 		red_id:red_id
		 	},function(result){
		 		if(callback)
		 		callback(result.result);
		 	})
		 },
		 //红包时候用 
		 send_msg:function(chat_url,message,param,siginfo,group_id,callback){
		 	var html_url = chat_url+'/message/sendChat?';
		 	html_url +='sigVer='+siginfo.sigVer;
		 	html_url +='&nonce='+siginfo.nonce;
		 	html_url +='&ts='+siginfo.ts;
		 	html_url +='&sig='+siginfo.sig;
		 	html_url +='&loginCode='+param.loginCode;
		 	html_url +='&groupCode='+group_id;
		 	html_url +='&groupId='+param.groupId;
		 	html_url +='&frUserId='+param.frUserId;
		 	html_url +='&frUserName='+param.frUserName;
		 	html_url +='&toUserId='+param.toUserId;
		 	html_url +='&isAdvisory='+1;
		 	html_url +='&message='+message;
		 	$http({
		 		url:html_url,
		 		method:'GET',
		 	}).success(function(data){
		 		if(callback)
		 		callback(data);
		 	})
		 },
		 //打开红包
		 open_red:function(red_id,callback){
		 	Http.post({
		 		method:'chat.group.openingred',
		 		red_id:red_id
		 	},function(result){
		 		if(callback)
		 		callback(result.result);
		 	})
		 },
		 update_groupNotice:function(group_id,group_notice,callback){
		 	Http.post({
		 		method:'chat.group.updateGroupNotice',
		 		group_id:group_id,
		 		group_notice:group_notice
		 	},function(result){
		 		if(callback)
		 		callback(result.result);
		 	})
		 },
		 search_member:function(group_id,key,callback){
		 	Http.post({
		 		method:'chat.group.searchmember',
		 		group_id:group_id,
		 		key:key
		 	},function(result){
		 		if(callback)
		 		callback(result.result);
		 	})
		 },
		 get_img:function(chat_url,param,siginfo,callback){
		 	var html_url = chat_url+'/message/getPhoto?';
		 	html_url +='sigVer='+siginfo.sigVer;
		 	html_url +='&nonce='+siginfo.nonce;
		 	html_url +='&ts='+siginfo.ts;
		 	html_url +='&sig='+siginfo.sig;
		 	html_url +='&loginCode='+param.loginCode;
		 	html_url +='&frUserId='+param.frUserId;
		 	html_url +='&fileName='+param.fileName;
		 	return html_url;
		},
		set_black:function(group_id,user_id,to_black,callback){
			Http.post({
				method:'chat.group.setblack',
				group_id:group_id,
				user_id:user_id,
				to_black:to_black
			},function(result){
				if(callback)
				callback(result.result);
				//0
			})
		},
		set_gag:function(group_id,user_id,to_gag,callback){
			Http.post({
				method:'chat.group.setgag',
				group_id:group_id,
				user_id:user_id,
				to_gag:to_gag
			},function(result){
				if(callback)
				callback(result.result);
			})
		},
		set_main:function(group_id,user_id,callback){
			Http.post({
				method:'chat.group.setmain',
				group_id:group_id,
				user_id:user_id,
			},function(result){
				if(callback)
				callback(result.result);
			})
		},
		send_chat:function(group_id,message,param,siginfo,callback){
			Http.post({
				method:'chat.group.sendchat',
				group_id:group_id,
				login_code:param.loginCode,
				fr_user_id:param.frUserId,
				fr_user_name:param.frUserName,
				group_code:param.groupId,
				message:message,
				is_advisory:1,
				sig_ver:siginfo.sigVer,
				nonce:siginfo.nonce,
				ts:siginfo.ts,
				sig:siginfo.sig
			},function(result){
				if(callback)
				callback(result.result);
			})
		},
		send_img:function(group_id,file,param,siginfo,callback){
			Http.post({
				method:'chat.group.sendphoto',
				group_id:group_id,
				login_code:param.loginCode,
				fr_user_id:param.frUserId,
				fr_user_name:param.frUserName,
				group_code:param.groupId,
				file:file,
				is_advisory:1,
				sig_ver:siginfo.sigVer,
				nonce:siginfo.nonce,
				ts:siginfo.ts,
				sig:siginfo.sig
			},function(result){
				if(callback)
				callback(result.result);
			})
		}
		};
	}

	factory.$inject = ['Http','$http'];
	return app.registerService("Exchange_interaction_chat", factory);
});